﻿//-----------------------------------------------------------------------
// <copyright file="Layouts.cs" company="LMT">
//     Copyright (c) by La Minh Thuận.
// </copyright>
// <author>thuanla1985@hotmail.com</author>
//-----------------------------------------------------------------------
namespace LMT.Db
{
    using System.Collections.Generic;

    /// <summary>
    /// Interface for all Ado Adapter.
    /// </summary>
    /// <typeparam name="T">an implement of IEntity</typeparam>
    public interface IDbAdapter<T> where T : IDbEntity, new()
    {
        /// <summary>
        /// Insert the parameter entity into database.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="autoMapId">if set to <c>true</c> : auto get lasted ID from DB to entity.</param>
        /// <returns>number of affected records</returns>
        int Insert(ref T entity, bool autoMapId);

        /// <summary>
        /// Inserts the specified entities.
        /// </summary>
        /// <param name="entities">The entities.</param>
        /// <returns>number of affected records</returns>
        int Insert(List<T> entities, bool autoId);

        /// <summary>
        /// Updates the parameter entity into database.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns>number of affected records</returns>
        int Update(T entity);

        /// <summary>
        /// Updates the list of entities.
        /// </summary>
        /// <param name="entities">The list entities.</param>
        /// <returns>number of affected records</returns>
        int Update(List<T> entities);

        /// <summary>
        /// Updates the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="whereCon">The where con.</param>
        /// <returns></returns>
        int Update(T entity, List<Condition> whereCon);

        /// <summary>
        /// Deletes the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns>number of affected records</returns>
        int Delete(T entity);

        /// <summary>
        /// Deletes the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="whereCon">The where con.</param>
        /// <returns></returns>
        int Delete(List<Condition> whereCon);

        /// <summary>
        /// Gets all data of T.
        /// </summary>
        /// <returns>List instance of "T"</returns>
        List<T> Select();

        /// <summary>
        /// Gets all data of T.
        /// </summary>
        /// <returns>List instance of "T"</returns>
        List<T> Select(T entity);

        /// <summary>
        /// Gets the with filter.
        /// </summary>
        /// <param name="whereCon">The where con.</param>
        /// <returns></returns>
        List<T> Select(List<Condition> whereCon);

        /// <summary>
        /// Gets data by primary keys.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns>instance of "T"</returns>
        T Key(T entity);
    }
}